package com.xhj.bigfactory.bigFactory.volatile0;
/**
 * -
 *
 * @author 周沫 @Date 2021-07-20 @Time 9:20
 */
public class Visibility {

  public static void main(String[] args) {
    CommonResource resource = new CommonResource();
    new Thread(
            () -> {
              System.out.println(Thread.currentThread().getName() + "come in...");
              resource.addTo60();
              System.out.println(
                  Thread.currentThread().getName() + ": resource.number = " + resource.number);
            },
            "AAA")
        .start();
    while (resource.number == 0) {
      System.out.print(".");
    }
  }
}

class CommonResource {

  volatile int number = 0;

  public void addTo60() {
    this.number = 60;
  }
}
